# Given data
import re
from datetime import datetime
ls = ["2019-07-10 至 2019-08-10","2020-01-01 至 2020-12-01"]

time_periods = []
work_days = 0

#将字符串日期转为datetime格式
for i, date in enumerate(ls):

    if '至今' in date:
        st_num = re.findall(r'\d+', date)
        ed_date = datetime.now()
        if len(st_num) == 2:
                st_num.append('1')
        st_date = datetime.strptime('/'.join(st_num), '%Y/%m/%d')

        time_periods.append([st_date, ed_date])

        # delta = (ed_date - st_date).days
        # work_days += delta
        # text['专业经验年限'][i] = str(int(delta/365*10+0.5)/10)+'年'

    else:
        nums = re.findall(r'\d+', date)
        date_len = len(nums) // 2

        if date_len == 2:
                day = ['1']
        elif date_len == 3:
                day = []

        st_date = datetime.strptime('/'.join(nums[:date_len] + day), '%Y/%m/%d')
        ed_date = datetime.strptime('/'.join(nums[date_len:] + day), '%Y/%m/%d')

        time_periods.append([st_date, ed_date])

        # delta = (ed_date - st_date).days
        # work_days += delta
        # text['专业经验年限'][i] = str(int(delta/365*10+0.5)/10)+'年'

#剔除重叠的日期
# 按照开始日期排序
time_periods.sort(key=lambda x: x[0])

# 合并重叠的时间段
merged_periods = []
for start, end in time_periods:
    if not merged_periods or start > merged_periods[-1][1]:
        merged_periods.append((start, end))
    else:
        merged_periods[-1] = (merged_periods[-1][0], max(merged_periods[-1][1], end))

# 计算天数
for start, end in merged_periods:
    delta = (end - start).days
    work_days += delta

print(work_days)